package com.michael.ims.gateway.common.util.matcher;

import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.Map;

public interface ServerWebExchangeMatcher {
    Mono<MatchResult> matches(ServerWebExchange var1);

    /**
     * The result of matching
     */
    class MatchResult {
        private final boolean match;
        private final Map<String, Object> variables;

        private MatchResult(boolean match, Map<String, Object> variables) {
            this.match = match;
            this.variables = variables;
        }

        public boolean isMatch() {
            return match;
        }

        /**
         * Gets potential variables and their values
         *
         * @return
         */
        public Map<String, Object> getVariables() {
            return variables;
        }


        public static Mono<ServerWebExchangeMatcher.MatchResult> match() {
            return match(Collections.emptyMap());
        }

        public static Mono<ServerWebExchangeMatcher.MatchResult> match(Map<String, Object> variables) {
            return Mono.just(new ServerWebExchangeMatcher.MatchResult(true, variables));
        }

        public static Mono<ServerWebExchangeMatcher.MatchResult> notMatch() {
            return Mono.just(new ServerWebExchangeMatcher.MatchResult(false, Collections.emptyMap()));
        }
    }
}
